﻿using System;

namespace Transformable_Engine_v2.Engine.Helper
{
    public static class Rounding
    {
        public static double Clamp(this double value, double minValue, double maxValue)
        {
            return value.MinClamp(minValue).MaxClamp(maxValue);
        }

        public static float Clamp(this float value, float minValue, float maxValue)
        {
            return value.MinClamp(minValue).MaxClamp(maxValue);
        }

        public static float MaxClamp(this float value, float maxValue)
        {
            if (value > maxValue)
                return maxValue;

            return value;
        }

        public static double MaxClamp(this double value, double maxValue)
        {
            if (value > maxValue)
                return maxValue;

            return value;
        }

        public static float MinClamp(this float value, float minValue)
        {
            if (value < minValue)
                return minValue;

            return value;
        }

        public static double MinClamp(this double value, double minValue)
        {
            if (value < minValue)
                return minValue;

            return value;
        }

        public static bool IsBetween(this float value, float minValue, float maxValue)
        {
            return value >= minValue && value <= maxValue;
        }

        public static bool IsBetweenExclusive(this float value, float minValue, float maxValue)
        {
            return value > minValue && value < maxValue;
        }

        public static double ClampToNearestMultipleOf(this double value, double multiple)
        {
            var result = Math.Round(value/multiple, 0)*multiple;
            return result;
        }
    }
}